package com.itheima.service.impl;

import com.itheima.dao.ActRuJobDao;
import com.itheima.pojo.ActRuJob;
import com.itheima.service.ActRuJobService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (ActRuJob)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:51
 */
@Service("actRuJobService")
public class ActRuJobServiceImpl implements ActRuJobService {
    @Resource
    private ActRuJobDao actRuJobDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id_ 主键
     * @return 实例对象
     */
    @Override
    public ActRuJob queryById(String id_) {
        return this.actRuJobDao.queryById(id_);
    }

    /**
     * 分页查询
     *
     * @param actRuJob 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActRuJob> queryByPage(ActRuJob actRuJob, PageRequest pageRequest) {
        long total = this.actRuJobDao.count(actRuJob);
        return new PageImpl<>(this.actRuJobDao.queryAllByLimit(actRuJob, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param actRuJob 实例对象
     * @return 实例对象
     */
    @Override
    public ActRuJob insert(ActRuJob actRuJob) {
        this.actRuJobDao.insert(actRuJob);
        return actRuJob;
    }

    /**
     * 修改数据
     *
     * @param actRuJob 实例对象
     * @return 实例对象
     */
    @Override
    public ActRuJob update(ActRuJob actRuJob) {
        this.actRuJobDao.update(actRuJob);
        return this.queryById(actRuJob.getId_());
    }

    /**
     * 通过主键删除数据
     *
     * @param id_ 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id_) {
        return this.actRuJobDao.deleteById(id_) > 0;
    }
}
